#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QGridLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPushButton *btn1 = new QPushButton("按钮1");
    QPushButton *btn2 = new QPushButton("按钮2");
    QPushButton *btn3 = new QPushButton("按钮3");
    QPushButton *btn4 = new QPushButton("按钮4");
    QPushButton *btn5 = new QPushButton("按钮5");
    QPushButton *btn6 = new QPushButton("按钮6");

    // 只有将按钮的sizepolicy给进行设置，给行设置的拉伸系数才会生效
    btn1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn5->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    btn6->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);


    QGridLayout *layout = new QGridLayout();

    // 按照两行三列进行摆放
    layout->addWidget(btn1, 0, 0);
    layout->addWidget(btn2, 0, 1);
    layout->addWidget(btn3, 0, 2);
    layout->addWidget(btn4, 1, 0);
    layout->addWidget(btn5, 1, 1);
    layout->addWidget(btn6, 1, 2);

    // 设置每列的拉伸系数，画面比例设置为1:1:5
    // 当拉伸系统设为0时，代表该列不参与拉伸
//    layout->setColumnStretch(0, 1);
//    layout->setColumnStretch(1, 1);
//    layout->setColumnStretch(2, 5);

    // 设置每行的拉伸系数
    layout->setRowStretch(0, 2);
    layout->setRowStretch(1, 5);


    this->setLayout(layout);
}

Widget::~Widget()
{
    delete ui;
}

